<?php

namespace App\Third;

use Qiniu\Auth as QiniuAuth;

class Qiniu
{
    /**
     * 生成上传凭证
     * @return string
     */
    public static function getToken()
    {
        $auth = new QiniuAuth(config('filesystems.disks.qiniu')['access_key'], config('filesystems.disks.qiniu')['secret_key']);

        $policy = array(
            'callbackBody' => 'key=$(key)&hash=$(etag)&bucket=$(bucket)&fsize=$(fsize)&name=$(x:name)',
            'callbackBodyType' => 'application/json'
        );

        return $auth->uploadToken(config('filesystems.disks.qiniu')['bucket'], null, config('filesystems.disks.qiniu')['url_time'], $policy, true);
    }
}
